<?php
//print_r($_GET);die;//Array ( [addr_id] => 7 )
include_once("../function.php");
extract($_GET);//$adr_id
$sql="select * from ts_address where addr_id='$addr_id'";
$res=mysqli_query($link,$sql);
if(is_object($res))
{
	if(mysqli_num_rows($res)==1)
	{
		$one=mysqli_fetch_assoc($res);
		$addr_d=$one['addr_defalut'];
		if($addr_d==1)
		{
			$sql="delete from ts_address where addr_id='$addr_id'";
			$res=mysqli_query($link,$sql);
			if($res)
			{
				if(mysqli_affected_rows($link)==1)
				{
					$sql="select * from ts_user where username='$_COOKIE[username]'";
					$res=mysqli_query($link,$sql);
					if(is_object($res))
					{
						$one1=mysqli_fetch_assoc($res);$uid=$one1['uid'];
					}
					$sql="select * from ts_address where u_id='$uid'";
					$res=mysqli_query($link,$sql);
					if(is_object($res))
					{
						$list=mysqli_fetch_assoc($res);
						{
							$sql="update ts_address set addr_defalut=1 where addr_id=$list[addr_id]";
							$res=mysqli_query($link,$sql);
							if($res)
							{
								if(mysqli_affected_rows($links)==1)
								{
									if(isset($color))
									{
									header("location:./order.php?type=$type&size=$size&num=$num&price=$price&color=$color&pid=$pid");exit;
									}
									else
									{
										header("location:./order.php?type=$type");exit;
									}
								}
								else
								{
									if(isset($color))
									{
									header("location:./order.php?type=$type&size=$size&num=$num&price=$price&color=$color&pid=$pid");exit;
									}
									else
									{
										header("location:./order.php?type=$type");exit;
									}
								}
							}
						}
					}
					if(isset($color))
						{
							header("location:./order.php?type=$type&size=$size&num=$num&price=$price&color=$color&pid=$pid");exit;
						}
						else
						{
							header("location:./order.php?type=$type");exit;
						}
				}

			}
		}
		else
		{
			$sql="delete from ts_address where addr_id='$addr_id'";
			$res=mysqli_query($link,$sql);
			if($res)
			{
				if(mysqli_affected_rows($res)==1)
				{
					if(isset($color))
									{
									header("location:./order.php?type=$type&size=$size&num=$num&price=$price&color=$color&pid=$pid");exit;
									}
									else
									{
										header("location:./order.php?type=$type");exit;
									}
				}
				else
				{
					if(isset($color))
									{
									header("location:./order.php?type=$type&size=$size&num=$num&price=$price&color=$color&pid=$pid");exit;
									}
									else
									{
										header("location:./order.php?type=$type");exit;
									}
				}
			}
		}
	}
}
?>